package com.sx.ems.codeGen;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class Gen {

    public static void main(String[] args) {
        String packageName = "com.sx.ems.service.mysql";
        String dirPath ="";
        generateByTables(dirPath, packageName, "sys_material");
    }

    private static void generateByTables(String dirPath, String packageName, String... tableNames) {
        GlobalConfig config = new GlobalConfig();
        String dbUrl = "jdbc:mysql://127.0.0.1:3306/management_sys";
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL).setUrl(dbUrl).
                setUsername("root").
                setPassword("root").
                setDriverName("com.mysql.jdbc.Driver");

        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setCapitalMode(true)
                .setRestControllerStyle(true)
                .setEntityLombokModel(false)
//                .setDbColumnUnderline(true)
                .setNaming(NamingStrategy.underline_to_camel)
                .entityTableFieldAnnotationEnable(true)
                .setInclude(tableNames);

        config.setActiveRecord(false)
                .setAuthor("zxx")
                .setOutputDir("/Users/zxx/code")
                .setFileOverride(true)
                .setBaseColumnList(true)
                .setBaseResultMap(true)
                .setOpen(true);

        boolean serviceNameStartWithI = false;
        if ( !serviceNameStartWithI ) {
            config.setServiceName("%sService");
        }
        new AutoGenerator().setGlobalConfig(config).setDataSource(dataSourceConfig).setStrategy(strategyConfig)
                .setPackageInfo(new PackageConfig().setParent(packageName)
                        .setController("controller")
                        .setEntity("entity")).execute();
    }



}
